using Admin2025.Application.common;
using Admin2025.Application.Dtos;
using Admin2025.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Admin2025.Api.Controllers;


[ApiController]
[Route("api/[controller]")]
public class DepartmentController : ControllerBase
{
    private readonly IAppDepartmentService _service;
    public DepartmentController(IAppDepartmentService service)
    {
        _service = service;
    }

    [HttpPost]
    public async Task<ApiResult> Create([FromBody] CreateDepartmentDto dto)
    {
        var res = await _service.CreateDepartmentAsync(dto);
        return Ok(res);
    }

    [HttpDelete("{id}")]
    public async Task<ApiResult> Delete(Guid id)
    {
        var res = await _service.DeleteDepartmentAsync(id);
        return Ok(res);
    }
    [HttpPut("{id}")]
    public async Task<IActionResult> Update(Guid id, [FromBody] UpdateDepartmentDto dto)
    {
        var result = await _service.UpdateDepartmentAsync(id, dto);
        return Ok(result);
    }

    [HttpPost("{id}/enable")]
    public async Task<IActionResult> Enable(Guid id)
    {
        var result = await _service.EnableDepartment(id);
        return Ok(result);
    }

    [HttpPost("{id}/disable")]
    public async Task<IActionResult> Disable(Guid id)
    {
        var result = await _service.DisableDepartment(id);
        return Ok(result);
    }
}